<%--
    Document   : modifCrenau
    Created on : 15 juin 2011, 14:36:16
    Author     : boomar
--%>

<%@page import="bdd.DBLink"%>
<%@page import="java.util.List"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
    "http://www.w3.org/TR/html4/loose.dtd">

<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>Ajout des Créneaux</title>
        <link type="text/css" href="css/jdpicker.css" rel="stylesheet" />
        <script src="js/ajoutCrenau.js" type="text/javascript"> </script>
        <script src="js/jquery.js" type="text/javascript"> </script>
        <script src="js/jquery.jdpicker.js" type="text/javascript"></script>
        <script  type="text/javascript">
            $(document).ready(function(){
                $('#date').jdPicker({
                    //date_format:"dd FF YYYY",
                    date_format:"dd/mm/YYYY",
                    month_names: ["Janvier", "F&eacute;vrier", "Mars", "Avril", "Mai", "Juin", "Juillet", "Ao&ucirc;t", "Septembre", "Novembre", "D&eacute;cembre"],
                    short_day_names: ["D", "L", "M", "M", "J", "V", "S"]
                });
                $('#dateDebut').jdPicker({
                    //date_format:"dd FF YYYY",
                    date_format:"dd/mm/YYYY",
                    month_names: ["Janvier", "F&eacute;vrier", "Mars", "Avril", "Mai", "Juin", "Juillet", "Ao&ucirc;t", "Septembre", "Novembre", "D&eacute;cembre"],
                    short_day_names: ["D", "L", "M", "M", "J", "V", "S"]
                });
                $('#dateFin').jdPicker({
                    //date_format:"dd FF YYYY",
                    date_format:"dd/mm/YYYY",
                    month_names: ["Janvier", "F&eacute;vrier", "Mars", "Avril", "Mai", "Juin", "Juillet", "Ao&ucirc;t", "Septembre", "Novembre", "D&eacute;cembre"],
                    short_day_names: ["D", "L", "M", "M", "J", "V", "S"]
                });
            });
        </script>
    </head>
    <body style="text-align:center;">
        <h1>Ajout des Créneaux</h1>

        <form method="POST" action ="#" style="text-align: center;">

            <!-- EC -->
            <div class="ec" style="display:block;">
                <table border="0" align="center">
                    <td align="left">
                        <label for="ec">EC : </label>
                    </td>
                    <td align="right" width="60">
                        <select id="selectEC" onchange ="selectIndexChanged(this.id)" >
                            <option value=""></option>
                            <%
                                        int idEc;

                                        int postedEc = (request.getParameter("ec") == null) ? 0 : Integer.parseInt(request.getParameter("ec"));

                                        DBLink dbLink = new DBLink();
                                        dbLink.connexion();

                                        String sql = "SELECT * FROM EC";
                                        dbLink.setPst(dbLink.getConnection().prepareStatement(sql));

                                        dbLink.setRs(dbLink.getPst().executeQuery());

                                        while (dbLink.getRs().next()) {
                                            idEc = dbLink.getRs().getInt("NUMEC");
                                            out.println("<option value =\"" + idEc + "\"" + (postedEc == idEc ? "SELECTED" : "") + "> " + dbLink.getRs().getString("LIBELLE") + " </option>");
                                        }
                            %>
                        </select>
                    </td>
                </table>
            </div>

            <!-- EC -->
            <div class="type" style="display:block;">
                <table border="0" align="center">
                    <td align="left" width="60">
                        <label for="ec">Type : </label>
                    </td>
                    <td align="right" width="60">
                        <select id="selectType" onchange ="selectIndexChanged(this.id)">
                            <option value=""></option>
                            <%
                                        int idType;

                                        int postedType = (request.getParameter("type") == null) ? 0 : Integer.parseInt(request.getParameter("type"));

                                        sql = "SELECT * FROM TYPE";
                                        dbLink.setPst(dbLink.getConnection().prepareStatement(sql));
                                        dbLink.setRs(dbLink.getPst().executeQuery());

                                        while (dbLink.getRs().next()) {
                                            idType = dbLink.getRs().getInt("NUMTYPE");
                                            out.println("<option value =\"" + idType + "\"" + (postedType == idType ? "SELECTED" : "") + "> " + dbLink.getRs().getString("LIBELLE") + " </option>");
                                        }
                            %>
                        </select>
                    </td>
                </table>
            </div>


            <!-- ENSEIGNANT -->
            <div class="enseignant" style="display:block;">
                <table border="0" align="center">
                    <td align="left">
                        <label for="enseignant">Enseignant : </label>
                    </td>
                    <td align="right" width="60">
                        <select id="selectEnseignant" onchange ="selectIndexChanged(this.id)">
                            <option value=""></option>
                            <%
                                        int idEnseignant;
                                        String enseignantNomPrenom;
                                        int postedEnseignant = (request.getParameter("enseignant") == null) ? 0 : Integer.parseInt(request.getParameter("enseignant"));

                                        sql = "SELECT * FROM ENSEIGNANT";
                                        dbLink.setPst(dbLink.getConnection().prepareStatement(sql));

                                        dbLink.setRs(dbLink.getPst().executeQuery());

                                        while (dbLink.getRs().next()) {
                                            idEnseignant = dbLink.getRs().getInt("NUMENSEIGNANT");
                                            enseignantNomPrenom = dbLink.getRs().getString("NOM") + " " + dbLink.getRs().getString("PRENOM");
                                            out.println("<option value =\"" + idEnseignant + "\"" + (postedEnseignant == idEnseignant ? "SELECTED" : "") + "> " + enseignantNomPrenom + " </option>");
                                        }
                            %>

                        </select>
                    </td>
                </table>
            </div>


            <!-- Salle -->
            <div class="salle" style="display:block;">
                <table border="0" align="center">
                    <td align="left">
                        <label for="salle">Salle : </label>
                    </td>
                    <td align="right" width="60">
                        <select id="selectSalle" onchange ="selectIndexChanged(this.id)">
                            <option value=""></option>
                            <%
                                        int idSalle;
                                        int postedSalle = (request.getParameter("salle") == null) ? 0 : Integer.parseInt(request.getParameter("salle"));

                                        sql = "SELECT * FROM SALLE";
                                        dbLink.setPst(dbLink.getConnection().prepareStatement(sql));

                                        dbLink.setRs(dbLink.getPst().executeQuery());

                                        while (dbLink.getRs().next()) {
                                            idSalle = dbLink.getRs().getInt("NUMSALLE");
                                            out.println("<option value =\"" + idSalle + "\"" + (postedSalle == idSalle ? "SELECTED" : "") + "> " + dbLink.getRs().getString("LIEU") + " </option>");
                                        }
                            %>
                        </select>
                    </td>
                </table>
            </div>

            <!--selectTypeInsert -->
            <div class="selectTypeInsert" id="selectTypeInsert" style="display:block;">
                <table border="0" align="center">
                    <tr>
                        <td align="left">
                            <label for="jour">Type Ajout :</label>
                        </td>
                        <td align="right">
                            <input type="radio" name ="selectTypeInsert" id="jourSelect" onclick="showDaySelect();" value="oneDay" checked /> Un jour
                            <input type="radio" name ="selectTypeInsert" id="intervalJourSelect" onclick="showIntervalSelect();" value="interval" /> Intervalle
                        </td>
                    </tr>
                </table>
            </div>
            
            <!--Jour-->
            <div class="jour" id="jour">
                <table border="0" align="center">
                    <tr>
                        <td align="left">
                            <label for="jour">Jour :</label>
                        </td>
                        <td align="right">
                            <input type="text" name="date" id="date" value="<%= ((request.getParameter("date") == null) ? "" : request.getParameter("date"))%>" onchange ="selectIndexChanged(this.id)" />
                        </td>
                    </tr>
                </table>
            </div>

            <!--IntervalJour-->
            <div class="intervalJour" id ="intervalJour" style="display:none;">
                <table border="0" align="center">
                    <tr>
                        <td align="left">
                            <label for="intervalJourDebut">Jour Début :</label>
                        </td>
                        <td align="right">
                            <input type="text" name="intervalJourDebut" id="dateDebut" value="<%= ((request.getParameter("intervalJourDebut") == null) ? "" : request.getParameter("intervalJourDebut"))%>" onchange ="selectIndexChanged(this.id)" />
                        </td>

                        <td align="left">
                            <label for="intervalJourFin">Jour Fin :</label>
                        </td>
                        <td align="right">
                            <input type="text" name="intervalJourFin" id="dateFin" value="<%= ((request.getParameter("intervalJourFin") == null) ? "" : request.getParameter("intervalJourFin"))%>" onchange ="selectIndexChanged(this.id)" />
                        </td>
                    </tr>
                    <tr align="right">
                        <td align="left">
                            <label for="jour">Jour de la semaine :</label>
                        </td>
                        <td>
                            <select id="selectWeekDay" onchange ="selectIndexChanged(this.id)">
                                <option value=""></option>
                                <option value="lundi">Lundi</option>
                                <option value="mardi">Mardi</option>
                                <option value="mercredi">Mercredi</option>
                                <option value="jeudi">Jeudi</option>
                                <option value="vendredi">Vendredi</option>
                                <option value="samedi">Samedi</option>
                                <option value="dimanche">Dimanche</option>
                            </select>
                        </td>
                    <tr/>
                </table>
            </div>

            <!-- Formation -->
            <div class="formation" style="display:block;">
                <table border="0" align="center">
                    <td align="left">
                        <label for="salle">Formation : </label>
                    </td>
                    <td align="right" width="60">
                        <select id="selectFormation" onchange="JavaScript:displayPromos(); selectIndexChanged(this.id);" >
                            <option value=""></option>
                            <%
                                        int idFormation;
                                        int postedFormation = (request.getParameter("formation") == null) ? 0 : Integer.parseInt(request.getParameter("formation"));

                                        sql = "SELECT * FROM FORMATION";
                                        dbLink.setPst(dbLink.getConnection().prepareStatement(sql));

                                        dbLink.setRs(dbLink.getPst().executeQuery());

                                        while (dbLink.getRs().next()) {
                                            idFormation = dbLink.getRs().getInt("NUMFORMATION");
                                            out.println("<option value =\"" + idFormation + "\"" + (postedFormation == idFormation ? "SELECTED" : "") + "> " + dbLink.getRs().getString("LIBELLE") + " " + dbLink.getRs().getString("NIVEAU") + " " + dbLink.getRs().getString("TYPEFORMATION") + " </option>");
                                        }

                                        dbLink.getConnection().close();
                            %>
                        </select>
                    </td>
                </table>
            </div>

            <!-- Promotion -->
            <div class="promotion" style="display:block;">
                <table border="0" align="center">
                    <td align="left">
                        <label for="salle">Promotion : </label>
                    </td>
                    <td align="right" width="60">
                        <div id="promotion">
                            <select id="selectPromotion" onchange ="JavaScript:selectIndexChanged(this.id)" >
                            </select>
                        </div>
                    </td>
                    <td>
                        <input type="text" id="selectedPromotion" name="selectedPromotion" style="width: 10px; visibility:hidden" value="<% out.print((request.getParameter("selectedPromotion") == null) ? "" : Integer.parseInt(request.getParameter("selectedPromotion"))); %>" />
                    </td>
                </table>
            </div>

            <!-- CRENEAUX -->
            <div align="center">
                <fieldset style="width:400px;">
                    <legend> Créneaux </legend>

                    <div style ="display: block" class="debut">

                        <table border="0" align="center" height="30" width="220">
                            <td>
                                <!-- HEURE DEBUT -->
                                <label for="debut">Début : </label>
                            </td>
                            <td align="left">
                                <select id="heureDebut" onchange ="selectIndexChanged(this.id)" >
                                    <%
                                                int heureDebut = (request.getParameter("heureDebut") == null) ? 0 : Integer.parseInt(request.getParameter("heureDebut"));
                                                String heureDebutValue;
                                                for (int i = 7; i < 20; i++) {
                                                    heureDebutValue = (i < 10 ? "0" + i : i).toString();
                                                    out.println("<option value =\"" + heureDebutValue + "\"" + (((i) == heureDebut) ? "SELECTED" : "") + "> " + heureDebutValue + " </option>");
                                                }
                                    %>
                                </select>
                            </td>
                            <td>
                                <label for="h">H</label>
                            </td>
                            <td align="left">
                                <select id="minuteDebut" onchange ="selectIndexChanged(this.id)" >
                                    <%
                                                int minuteDebut = (request.getParameter("minuteDebut") == null) ? 0 : Integer.parseInt(request.getParameter("minuteDebut"));
                                                String minuteDebutValue;
                                                for (int i = 0; i < 4; i++) {
                                                    minuteDebutValue = (i == 0 ? "00" : i * 15).toString();
                                                    out.println("<option value =\"" + minuteDebutValue + "\" " + (((15 * i) == minuteDebut) ? "SELECTED" : "") + "> " + minuteDebutValue + " </option>");
                                                }
                                    %>
                                </select>
                            </td>
                        </table>
                    </div>

                    <div style ="display: block" class="fin">
                        <table border="0" align="center" >
                            <td>
                                <!-- HEURE FIN -->
                                <label for="fin">Fin : </label>
                            </td>
                            <td align="left">
                                <select id="heureFin" onchange ="selectIndexChanged(this.id)" >
                                    <%
                                                int heureFin = (request.getParameter("heureFin") == null) ? 0 : Integer.parseInt(request.getParameter("heureFin"));
                                                String heureFinValue;
                                                for (int i = 7; i < 20; i++) {
                                                    heureFinValue = (i < 10 ? "0" + i : i).toString();
                                                    out.println("<option value =\"" + heureFinValue + "\"" + (((i) == heureFin) ? "SELECTED" : "") + "> " + heureFinValue + " </option>");
                                                }
                                    %>
                                </select>
                            </td>
                            <td>
                                <label for="h">H</label>
                            </td>
                            <td align="left">
                                <select id="minuteFin" onchange ="selectIndexChanged(this.id)" >
                                    <%
                                                int minuteFin = (request.getParameter("minuteFin") == null) ? 0 : Integer.parseInt(request.getParameter("minuteFin"));
                                                String minuteFinValue;
                                                for (int i = 0; i < 4; i++) {
                                                    minuteFinValue = (i == 0 ? "00" : i * 15).toString();
                                                    out.println("<option value =\"" + minuteFinValue + "\"" + (((15 * i) == minuteDebut) ? " SELECTED " : "") + "> " + minuteFinValue + " </option>");
                                                }
                                    %>
                                </select>
                            </td>
                        </table>
                    </div>
                </fieldset>
            </div>

            <br/>

            <input type="button" id="btnValider" value="Valider" onclick ="JavaScript:submitForm();">
            <img alt="Chargement" id="loadingGIF" src="images/loading32-1.gif" style="visibility: hidden" />
            <input id="btnAnnuler" type="reset" value="Annuler" >

            <div id="alert">
            </div>

            <div id="responseUpdate">
            </div>
        </form>
    </body>
</html>
